package me.moscrop.RootCommand.commands;

import me.moscrop.RootCommand.utilities.Chat;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Time {
	
	public enum times
	{
		MORNING, DAY, SUNSET, NIGHT, SUNRISE, NULLVALUE;

		private static times available(String str)
	    {
	        try {
	            return valueOf(str.toUpperCase());
	        } 
	        catch (Exception ex) {
	            return NULLVALUE;
	        }
	    }   
	}

	
	public static boolean time(CommandSender sender, Command command, String label, String[] args) {
		if (!(sender instanceof Player)) {
			sender.sendMessage(" Command must be run in game.");
			return true;
		}
		
		World world;
		String type;
		Player player = (Player) sender;
		
		if (args.length >= 1) {
			type = args[0];
		} else {
			return false;
		}
		
		if (args.length >= 2) {
			world = Bukkit.getWorld(args[1]);
			if (world != null) return false;
		} else {
			world = player.getWorld();
		}
		
		Chat.messageAll(player, ChatColor.DARK_GRAY + " Set Time in " + ChatColor.WHITE + world.getName() + ChatColor.DARK_GRAY +  " to " + ChatColor.WHITE + type);
		
		switch (times.available(type)) {	
			case MORNING:			
				return Time.setTime(world, 0);
			case DAY:			
				return Time.setTime(world, 6000);	
			case SUNSET:			
				return Time.setTime(world, 12500);
			case NIGHT:			
				return Time.setTime(world, 15000);
			case SUNRISE:			
				return Time.setTime(world, 22500);
			default:
				return Time.setTime(world, Integer.parseInt(type));
		}
				
	}

	private static boolean setTime(World world, int ammount) {
		world.setTime(ammount);		
		return true;	
	}

}
